/*
 * GeneticInfoPanel.java
 *
 * Created on 24 kwiecień 2008, 11:03
 */

package flp.gui.view.random;

import flp.Layout;
import flp.solvers.random.RandomSettings;

/**
 * Klasa reprezentujaca panel obrazujacy dane liczbowe
 * dla algorytmu losowego.
 * 
 * @author  Necro
 */
public class RandomInfoPanel extends javax.swing.JPanel 
{
    public RandomInfoPanel()
    {
        initComponents();
    }
    
    /**
     * Metoda inicjalizujaca nowy panel.
     */
    public RandomInfoPanel(RandomSettings settings) 
    {
        this();
        
        maxIterValueLabel.setText("" + settings.getIterations());
        
        resultLabel.setVisible(false);
        resultValueLabel.setVisible(false);

        iterationProgressBar.setMinimum(0);
        iterationProgressBar.setMaximum(settings.getIterations());
        iterationProgressBar.setStringPainted(true);
        iterationProgressBar.setToolTipText("Pasek postępu dla wykonywanych iteracji");
    }
 
     /**
     * Metoda ustawiajaca nowa wartosc tekstowa pola
     * z zegarem mierzacym czas trwania obliczen.
     * 
     * @param newText Nowy tekst dla etykiety.
     */
    public void setTimeLabelText(String newText){
        this.timerLabel.setText(newText);
    }
 
        /**
     * Metoda aktualizujaca etykiety panelu.
     * 
     * @param newIter Numer aktualnej iteracji.
     * @param newTopCost Najlepszy koszt dla aktualnej proby.
     */
    public void updateValues(int newIter, int newTopCost){
       topCostValueLabel.setText(Integer.toString(newTopCost));
       markOnBar(newIter);
    }

     /**
     * Metoda wywolywana po zakonczeniu obliczen dla danego przypadku
     * wyswietla dla niego rozwiazanie problemu.
     * 
     * @param bestLayout Najlepszy Layout znaleziony podczas optymalizacji.
     */
    public void showResult(Layout bestLayout){
       resultValueLabel.setText(""+bestLayout.toString2()+"    cost: "+topCostValueLabel.getText());
       topCostLabel.setEnabled(false);
       topCostValueLabel.setEnabled(false);
       
       resultLabel.setVisible(true);
       resultValueLabel.setVisible(true);
       
    }

     /**
     * Metoda zaznaczajaca postep na pasku postepu.
     * 
     * @param tryVal Wartosc do zaznaczenia.
     */
    private void markOnBar(int iteration) {
        iterationProgressBar.setValue(iteration);
        iterationProgressBar.setString(iteration + " / " + maxIterValueLabel.getText());
    }
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titlePrefixLabel = new javax.swing.JLabel();
        titleLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        timerLabel = new javax.swing.JLabel();
        resultValueLabel = new javax.swing.JLabel();
        resultLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        topCostLabel = new javax.swing.JLabel();
        topCostValueLabel = new javax.swing.JLabel();
        iterationProgressBar = new javax.swing.JProgressBar();
        geneticSettingsPanel = new javax.swing.JPanel();
        maxIterValueLabel = new javax.swing.JLabel();
        maxIterLabel = new javax.swing.JLabel();

        titlePrefixLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        titlePrefixLabel.setText("Do optymalizacji zastosowano:");

        titleLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        titleLabel.setForeground(new java.awt.Color(0, 102, 0));
        titleLabel.setText("ALGORYTM LOSOWY");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel1.setForeground(new java.awt.Color(0, 0, 102));
        jLabel1.setText("Czas trwania obliczeń:");

        timerLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        timerLabel.setForeground(new java.awt.Color(0, 0, 102));
        timerLabel.setText("00:00");

        resultValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        resultValueLabel.setForeground(new java.awt.Color(0, 0, 102));
        resultValueLabel.setText("przykladowy wynik");

        resultLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        resultLabel.setText("WYNIK:");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Monitor wartości"));

        topCostLabel.setText("Najlepszy znaleziony koszt:");

        topCostValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        topCostValueLabel.setText("0");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(topCostLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(topCostValueLabel)
                .addContainerGap(110, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(topCostLabel)
                    .addComponent(topCostValueLabel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        geneticSettingsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Ustawienia algorytmu"));

        maxIterValueLabel.setFont(new java.awt.Font("Tahoma", 1, 11));
        maxIterValueLabel.setText("0");

        maxIterLabel.setText("Maksymalna ilość iteracji:");

        javax.swing.GroupLayout geneticSettingsPanelLayout = new javax.swing.GroupLayout(geneticSettingsPanel);
        geneticSettingsPanel.setLayout(geneticSettingsPanelLayout);
        geneticSettingsPanelLayout.setHorizontalGroup(
            geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(geneticSettingsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(maxIterLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(maxIterValueLabel)
                .addContainerGap(108, Short.MAX_VALUE))
        );
        geneticSettingsPanelLayout.setVerticalGroup(
            geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, geneticSettingsPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(geneticSettingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxIterLabel)
                    .addComponent(maxIterValueLabel))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titlePrefixLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(titleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(timerLabel)
                .addGap(12, 12, 12))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(iterationProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(resultLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(resultValueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(geneticSettingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(titlePrefixLabel)
                    .addComponent(titleLabel)
                    .addComponent(timerLabel)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(iterationProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(geneticSettingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(resultLabel)
                    .addComponent(resultValueLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel geneticSettingsPanel;
    private javax.swing.JProgressBar iterationProgressBar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel maxIterLabel;
    private javax.swing.JLabel maxIterValueLabel;
    private javax.swing.JLabel resultLabel;
    private javax.swing.JLabel resultValueLabel;
    private javax.swing.JLabel timerLabel;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JLabel titlePrefixLabel;
    private javax.swing.JLabel topCostLabel;
    private javax.swing.JLabel topCostValueLabel;
    // End of variables declaration//GEN-END:variables
    
}
